package com.ai.module.user.controller;

import com.ai.module.chat.common.ano.NoAuth;
import com.ai.module.chat.common.enu.AliFileSource;
import com.ai.module.user.domain.entity.UserRobotEntity;
import com.ai.module.user.domain.req.UserRobotReq;
import com.ai.module.user.domain.vo.UserRobotVo;
import com.ai.module.user.domain.vo.UserTaskVo;
import com.ai.module.chat.common.domain.vo.chat.ChatContent;
import com.ai.module.user.service.UserRobotService;
import com.ai.module.user.service.UserTaskService;
import com.ai.common.BaseResp;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author: MrHe
 * @create: 2024-01-08 23:47
 * @description: 查询用户相关的AI数据信息
 **/
@RestController
@RequestMapping("/member/robot")
@Api(tags = "用户AI信息")
public class UserRobotController {
    @Autowired
    private UserRobotService robotService;

    @Autowired
    private UserTaskService userTaskService;

    @GetMapping
    @ApiOperation("查询所有的AI")
    @NoAuth
    public List<UserRobotVo> findAll(){
       return robotService.findALL();
    }

    @PostMapping("findDefaultRobot")
    @ApiOperation("查询默认AI")
    public UserRobotVo findDefaultRobot(@RequestBody UserRobotReq userRobotReq){

       return robotService.findDefaultRobot(userRobotReq);
    }

    @PostMapping("chatInfoList")
    @ApiOperation("查询聊天AI记录")
    public IPage<ChatContent> chatInfoList(@RequestBody UserRobotReq userTaskReq){
        return robotService.chatInfoList(userTaskReq);
    }


    @PostMapping("updateRobot")
    @ApiOperation("修改AI信息")
    public boolean updateRobotName(@RequestBody UserRobotReq robotReq){
        return robotService.updateRobot(robotReq);
    }

    @PostMapping("create")
    @ApiOperation("创建AI信息")
    public String create(@RequestBody UserRobotReq robotReq){
        return robotService.create(robotReq);
    }


    @PostMapping("/findImageList")
    @ApiOperation("查询绘画AI数据")
    public Page<UserTaskVo> findByRobot(@RequestBody  UserRobotReq req){
        return userTaskService.findByRobot(req);

    }


    @PostMapping("/uploadImage")
    @NoAuth
    @ApiOperation("背景图片上传")
    public BaseResp<String> uploadImage(@ApiParam("文件")   @RequestParam("file") MultipartFile file,
                                @ApiParam(value = "业务id, AIid或者用户id", required = false)    @RequestParam(value = "businessId", required = false)  String businessId,
                                @ApiParam(value = "上传类型", required = true, example="ROBOT_AVATAR")
                              @RequestParam("imageSource") AliFileSource imageSource){
        return robotService.uploadImage((MultipartFile) file,businessId,imageSource);
    }

    @GetMapping("findByRobotId")
    @ApiOperation("查询AI信息")
    public UserRobotVo findByRobotId(@ApiParam(value = "AIID", required = true) String robotId){
        return robotService.findByRobotId(robotId);
    }



    @DeleteMapping("/deleteRobot")
    @ApiOperation("删除AI")
    public void deleteRobot(@RequestBody  UserRobotReq req){
         robotService.deleteRobot(req);
    }


    @GetMapping("findSessions")
    @ApiOperation("查询所有的AI")
    @NoAuth
    public List<UserRobotEntity> findSessions(){
        return robotService.findSessions();
    }

}
